<template>
    <!-- 入库 -->
    <el-dialog title="批量审批" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="auto">
            <c-form-template label-position="left">
                <el-col :span="24">
                    <el-form-item label="请选择审批结果：" prop="flag">
                        <el-radio-group v-model="ruleForm.flag">
                            <el-radio :label="true">通过</el-radio>
                            <el-radio :label="false">驳回</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="ruleForm.flag === false">
                    <el-form-item label="驳回原因：" style="width:322px" prop="rejection">
                        <el-input v-model="ruleForm.rejection"></el-input>
                    </el-form-item>
                </el-col>
            </c-form-template>
        </el-form>
        <span slot="footer">
            <el-button :loading="loading" @click="handleClose">取 消</el-button>
            <el-button :loading="loading" type="primary" @click="handleSubmit">确 定</el-button>
        </span>
    </el-dialog>
</template>
<script>
export default {
    data () {
        return {
            dialogVisible: false,
            loading: false,
            ruleForm: {},
            rules: {
                rejection: [{ required: true, message: "请输入驳回原因", trigger: "blur" }],
                flag: [{ required: true, message: "请选择审批结果", trigger: "blur" }]
            },
            list: []
        };
    },
    mounted () {
    },
    methods: {
        handleSubmit () {
            this.$refs.ruleForm.validate((valid) => {
                if (valid) {
                    this.$confirm("是否确认批量审批?", "提示", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning",
                    }).then(() => {
                        let data = [];
                        let url = "/product/listing/batchApproval";
                        this.list.forEach((item) => {
                            data.push({
                                "flag": this.ruleForm.flag,
                                "id": item.id,
                                "operator": "",
                                "rejection": this.ruleForm.rejection
                            })
                        });
                        this.$post({ url, data }).then(
                            () => {
                                this.$message.success("操作成功");
                                this.handleClose();
                                this.$parent.$parent.tableList();
                                this.loading = false;
                            },
                            () => {
                                this.loading = false;
                            }
                        );
                    })
                }
            })
        },
        handleOpen (list) {
            this.list = list
            this.dialogVisible = true;
        },
        handleClose () {
            this.ruleForm = {};
            this.dialogVisible = false;
        },
    },
};
</script>
